package taller2.view.components;

import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JToggleButton;

import taller2.controller.listeners.AutoscrollSpeedListener;
import taller2.controller.listeners.HighlightMenuListener;
import taller2.view.menus.CodeBrowser;

public class HighlightBar{
	private JToggleButton highlightPrevButton;
    private JToggleButton highlightNextButton;
    private JToggleButton resetButton;
    private SwitchBox autohighlightButton;
    private	JSlider autohighlightBar;
    
    private JPanel firstRow,secondRow;
    
    public HighlightBar(CodeBrowser browser,CharacterBox panelTxt) {
    	autohighlightBar = new JSlider(10, 100);
    	autohighlightBar.addChangeListener(new AutoscrollSpeedListener(browser));

    	
    	HighlightMenuListener handler = new HighlightMenuListener(this, browser, panelTxt);
    	highlightPrevButton = createButton("prev",handler);
        highlightNextButton = createButton("next",handler);
        resetButton = createButton("reset",handler);

        autohighlightButton = new SwitchBox("on","off",browser);

        firstRow = new JPanel();
        firstRow.add(autohighlightBar);
        firstRow.add(autohighlightButton);
        
        secondRow = new JPanel();
        secondRow.add(highlightPrevButton);
        secondRow.add(highlightNextButton);
        secondRow.add(resetButton);        
    }
    
    // unselects all buttons
    public void unselectButtons(){
	highlightPrevButton.setSelected(false);
	highlightNextButton.setSelected(false);
	resetButton.setSelected(false);      
    }             
     
    public void setAutohighlightButton(boolean state){
    	autohighlightButton.setSelected(state);
    }
    
    // returns true if the object is the highlight previous button (for handler only!!!)
    public boolean isHighlightPrevButton(Object button){
            return (button == highlightPrevButton);
    }
   
    // returns true if the object is the highlight next button (for handler only!!!)
    public boolean isHighlightNextButton(Object button){
            return (button == highlightNextButton);
    }
  
    // returns true if the object is the reset button (for handler only!!!)
    public boolean isResetButton(Object button){
            return (button == resetButton);
    }
    
    // adds a standard button
    private JToggleButton createButton(String text,HighlightMenuListener handler){
            JToggleButton button = new JToggleButton(text);
            button.addActionListener(handler);              
            return button;
    }

	public JPanel getFirstRow() {
		return firstRow;
	}

	public JPanel getSecondRow() {
		return secondRow;
	}
}
